package com.competition.commgr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.competition.commgr.domain.vo.RegistrationVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.competition.common.annotation.Log;
import com.competition.common.core.controller.BaseController;
import com.competition.common.core.domain.AjaxResult;
import com.competition.common.enums.BusinessType;
import com.competition.commgr.domain.Registration;
import com.competition.commgr.service.IRegistrationService;
import com.competition.common.utils.poi.ExcelUtil;
import com.competition.common.core.page.TableDataInfo;

/**
 * 报名Controller
 * 
 * @author cui
 * @date 2025-02-01
 */
@RestController
@RequestMapping("/commgr/registration")
public class RegistrationController extends BaseController
{
    @Autowired
    private IRegistrationService registrationService;

    /**
     * 查询报名列表
     */
    @PreAuthorize("@ss.hasPermi('commgr:registration:list')")
    @GetMapping("/list")
    public TableDataInfo list(RegistrationVo registration)
    {
        startPage();
        List<RegistrationVo> list = registrationService.selectRegistrationVoList(registration);
        return getDataTable(list);
    }

    /**
     * 导出报名列表
     */
    @PreAuthorize("@ss.hasPermi('commgr:registration:export')")
    @Log(title = "报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Registration registration)
    {
        List<RegistrationVo> list = registrationService.selectRegistrationVoList(registration);
        ExcelUtil<RegistrationVo> util = new ExcelUtil<RegistrationVo>(RegistrationVo.class);
        util.exportExcel(response, list, "报名数据");
    }

    /**
     * 获取报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('commgr:registration:query')")
    @GetMapping(value = "/{regId}")
    public AjaxResult getInfo(@PathVariable("regId") Long regId)
    {
        return success(registrationService.selectRegistrationByRegId(regId));
    }

    /**
     * 新增报名
     */
    @PreAuthorize("@ss.hasPermi('commgr:registration:add')")
    @Log(title = "报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegistrationVo registration)
    {
        System.out.println("--------------"+registration);
        return toAjax(registrationService.insertRegistration(registration));
    }

    /**
     * 修改报名
     */
    @PreAuthorize("@ss.hasPermi('commgr:registration:edit')")
    @Log(title = "报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Registration registration)
    {
        return toAjax(registrationService.updateRegistration(registration));
    }

    /**
     * 删除报名
     */
    @PreAuthorize("@ss.hasPermi('commgr:registration:remove')")
    @Log(title = "报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regIds}")
    public AjaxResult remove(@PathVariable Long[] regIds)
    {
        return toAjax(registrationService.deleteRegistrationByRegIds(regIds));
    }
}
